package com.ruoyi.system.carsale.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.carsale.domain.CarFct;
import com.ruoyi.system.carsale.service.ICarFctService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 品牌车系Controller
 * 
 * @author ruoyi
 * @date 2024-07-18
 */
@RestController
@RequestMapping("/carFct")
public class CarFctController extends BaseController
{
    @Autowired
    private ICarFctService carFctService;

    /**
     * 查询品牌车系列表
     */
    @RequiresPermissions("system:carFct:list")
    @GetMapping("/list")
    public TableDataInfo list(CarFct carFct)
    {
        startPage();
        List<CarFct> list = carFctService.selectCarFctList(carFct);
        return getDataTable(list);
    }

    /**
     * 导出品牌车系列表
     */
    @RequiresPermissions("system:carFct:export")
    @Log(title = "品牌车系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarFct carFct)
    {
        List<CarFct> list = carFctService.selectCarFctList(carFct);
        ExcelUtil<CarFct> util = new ExcelUtil<CarFct>(CarFct.class);
        util.exportExcel(response, list, "品牌车系数据");
    }

    /**
     * 获取品牌车系详细信息
     */
    @RequiresPermissions("system:carFct:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(carFctService.selectCarFctById(id));
    }

    /**
     * 新增品牌车系
     */
    @RequiresPermissions("system:carFct:add")
    @Log(title = "品牌车系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarFct carFct)
    {
        carFctService.insertCarFct(carFct);
        CarFct c = new CarFct();
        c.setId(carFct.getId());
        c.setFctId(carFctService.getMaxFctId()+1);
        return toAjax(carFctService.updateCarFct(c));
    }

    /**
     * 修改品牌车系
     */
    @RequiresPermissions("system:carFct:edit")
    @Log(title = "品牌车系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarFct carFct)
    {
        return toAjax(carFctService.updateCarFct(carFct));
    }

    /**
     * 删除品牌车系
     */
    @RequiresPermissions("system:carFct:remove")
    @Log(title = "品牌车系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carFctService.deleteCarFctByIds(ids));
    }
}
